package com.lgk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lgk.domain.Role;
import com.lgk.mapper.RoleMapper;
import com.lgk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    //分页查询
    @Override
    public PageInfo<Role> getPageRole(Integer pageNum) {
        PageHelper.startPage(pageNum, 6);
        List<Role> all = roleMapper.getAllRole();
        return new PageInfo<>(all, 5);
    }

    //添加
    @Override
    public void addRole(Role role) {
        roleMapper.addRole(role);
    }

    //id的获取
    @Override
    public Role getById(Integer id) {
        return roleMapper.getById(id);
    }

    //修改用户
    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    //删除用户
    @Override
    public void deleteRole(Integer id) {
        roleMapper.deleteRole(id);
    }

    //名字模糊查询
    @Override
    public PageInfo<Role> getPageByName(String name, Integer pageNum) {
        PageHelper.startPage(pageNum, 6);
        List<Role> allNameRole = roleMapper.getByNameAllRole(name);
        return new PageInfo<>(allNameRole, 5);
    }

    //获取全部角色
    @Override
    public List<Role> geRoleAll() {
        return roleMapper.getAllRole();
    }
}
